package mqtt

import (
	"github.com/gin-gonic/gin"
	"github.com/goccy/go-json"
	"time"
	"zsgGin/common"
)

// PubMqtt 发送数据
func PubMqtt(g *gin.Context) {
	msg := &Message{
		ClientID: UserName,
		Type:     "text",
		Data:     "Hello zsg",
		Topic:    "mqtt",
		Time:     time.Now().Unix(),
	}
	data, err := json.Marshal(msg)
	if err != nil {
		common.FailWithMessage("数据解析错误,原因+"+err.Error(),g)
	}
	err = MqClient.Publish("mqtt", 1, false, data)
	if err != nil {
		common.FailWithMessage("发送错误,原因+"+err.Error(),g)
	}
}